//
//  CRAddressController.m
//  CRChatRoom
//
//  Created by lanou3g on 15/11/25.
//  Copyright © 2015年 SecondGroup. All rights reserved.
//

#import "CRAddressController.h"
@import CoreLocation;
@import MapKit;

@interface CRAddressController () <CLLocationManagerDelegate>

@property (nonatomic, strong) CLLocationManager *locationManager;

/**
 *  显示地理位置信息
 */
@property (nonatomic, strong) UITextField *addressInfo;


@end

@implementation CRAddressController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // 实例化LocationManager对象
    self.locationManager = [[CLLocationManager alloc] init];
    // 指定代理对象
    self.locationManager.delegate = self;
    // 开始更新位置信息
    [self.locationManager startUpdatingLocation];
    // 向用户发起定位请求
    [self.locationManager requestAlwaysAuthorization];
 

}


#pragma mark ---- Location Manager Delegate
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations
{
    // 停止更新位置信息
    [self.locationManager stopUpdatingLocation];

    // 地理编码
    CLGeocoder *geocoder = [[CLGeocoder alloc] init];
    [geocoder reverseGeocodeLocation:locations.lastObject completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {

        // 地标
        CLPlacemark *placemark = [placemarks lastObject];
        // 地址信息字典
        NSDictionary *addressDict = [placemark addressDictionary];

        NSLog(@"%@", [addressDict[@"FormattedAddressLines"] lastObject]);

    }];
}

@end














